/**
 * 
 */
package com.et114.components.junit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.util.Assert;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.et114.core.common.CONST;
//import com.et114.core.control.AllwaysInitServlet ;

import junit.framework.TestCase;

/*
 * @author guanhw
 */
 public class BaseTestCase extends TestCase {
	private ClassPathXmlApplicationContext applicationContext = null;
	protected Log logger = LogFactory.getLog( this.getClass( ) );
	
	public void setUp() {
		try {
			//AllwaysInitServlet.initAppConfig() ;
		}
		catch ( Exception e ) {
			logger.error(  e.getMessage() , e  ) ; 
		}
		
		if ( getSpringConfigLocations() == null ) {
			applicationContext = new ClassPathXmlApplicationContext( 
					new String[]{ CONST.DEFAULT_SPRING_CONFIG_LOC } ); logger.info ( "??????????" ) ;
		}
		else {
			applicationContext = new ClassPathXmlApplicationContext( 
					getSpringConfigLocations( ) );			
		}
	}

	protected Object getBean( String bean ) {
		Assert.state( !( bean == null || "".equals( bean.trim() ) ) , "beanName 不能为空！" ) ; 
		return this.getApplicationContext().getBean( bean ) ; 
	}
	

	
	protected ClassPathXmlApplicationContext getApplicationContext() {
		return applicationContext;
	}

	
	protected String[] getSpringConfigLocations () {
		return null;
	}
}
